package com.csk.zsk.http.action;

import java.io.UnsupportedEncodingException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.csk.zsk.commons.action.AjaxActionSupport;
import com.csk.zsk.commons.utils.web.struts2.Struts2Utils;
import com.csk.zsk.http.util.HttpclientUtil;
@Controller
@Scope("prototype")
public class HttpResponseAction extends AjaxActionSupport {

	private static final long serialVersionUID = -2843737143095165651L;
	
	private String url = "";

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	public void getJsonContent(){
		String json = HttpclientUtil.get(url);
		Struts2Utils.renderJson(json);
	}
	
	public void getContent(){
		
		String txt = HttpclientUtil.get(url);
		Struts2Utils.renderText(txt);
		
	}
	
	public void getHtmlContent(){
		try{
			String txt = HttpclientUtil.get(url);
			Struts2Utils.renderHtml(new String(txt.getBytes("GBK"),"UTF-8"));
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
	}
	
	public static void main(String[] args) throws Exception{
		String txt = HttpclientUtil.get("http://www.kuaidi100.com/frame/",null,"utf-8");
		txt = new String(txt.getBytes("GBK"),"UTF-8");  
		System.out.print(txt);
	}
	
	
	
	
	
}
